#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QColorDialog>
#include <QFontDialog>
#include <QInputDialog>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    //直接在构造函数中进行设置，或者再调用set方法进行设置
    QMessageBox* msgBox = new QMessageBox(QMessageBox::Icon::Question,"Basic","basic test",QMessageBox::Ok | QMessageBox::Cancel,this);
    msgBox->show();

    //直接调用静态函数
    QMessageBox::critical(this,"Critical","critical test",QMessageBox::Ok | QMessageBox::Cancel);

    msgBox->setAttribute(Qt::WA_DeleteOnClose);
}

//getColor(静态函数，无需通过对象调用)和exec/show都会触发出颜色对话框
void MainWindow::on_pushButton_2_clicked()
{
    //QColorDialog* dialog = new QColorDialog(this);
    //qDebug() << dialog->getColor();
//    dialog->exec();
//    dialog->setAttribute(Qt::WA_DeleteOnClose);

    QColor initalColor(255,0,0);
    QColor color = QColorDialog::getColor(initalColor);

    //获取颜色
    int r,g,b;
    color.getRgb(&r,&g,&b);

    //设置按钮的字体颜色
    ui->pushButton_2->setStyleSheet("color: rgb(" + QString::number(r) + ","
                                   + QString::number(g) + "," + QString::number(b) + ")");

}

void MainWindow::on_pushButton_3_clicked()
{
    bool ok;
    QFont font = QFontDialog::getFont(&ok, this);   //直接使用静态函数
    if (ok)
    {
        // font is set to the font the user selected
        ui->pushButton_3->setFont(font);
    }
    else
    {
        return;
        // the user canceled the dialog; font is set to the default
        // application font, QApplication::font()
    }

}



void MainWindow::on_pushButton_4_clicked()
{
    bool ok;
    int res = QInputDialog::getInt(this, "INT", "input integer", 10, 0, 100, 2, &ok);
    if(ok)
    {
       qDebug() << res;
    }
}
